package org.shop.controller.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.shop.entity.security.MyUserDetail;
import org.shop.service.StatisticalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class WebStatisticalController {
	@Autowired
    private StatisticalService statisticalService;
	
	@RequestMapping("web/monthPurchaseStatistical")
	@ResponseBody
	public List<Map<String, Object>> webMonthPurchaseStatistical(){
		MyUserDetail ud = (MyUserDetail) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		Map<String, Object> paramMap=new HashMap<String, Object>();
		paramMap.put("merchantId", ud.getMerchantId());
		return statisticalService.getGoodsMonthPurchaseCount(paramMap);
	}
	@RequestMapping("web/dayPurchaseStatistical")
	@ResponseBody
	public List<Map<String, Object>> webDayPurchaseStatistical(){
		MyUserDetail ud = (MyUserDetail) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		Map<String, Object> paramMap=new HashMap<String, Object>();
		paramMap.put("merchantId", ud.getMerchantId());
		return statisticalService.getGoodsDayPurchaseCount(paramMap);
	}
	
	
	@RequestMapping("web/goodsPurchaseStatistical")
	@ResponseBody
	public List<Map<String, Object>> goodsPurchaseStatistical(){
		MyUserDetail ud = (MyUserDetail) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		Map<String, Object> paramMap=new HashMap<String, Object>();
		paramMap.put("merchantId", ud.getMerchantId());
		return statisticalService.getGoodsPurchaseCount(paramMap);
	}
	
	/**
	 * 商家获取商品的游览量
	 * @param req
	 * @return
	 */
	@RequestMapping("web/getMerchantOfGoodsPageView")
	@ResponseBody
	public List<Map<String,Object>> getMerchantOfGoodsPageView(HttpServletRequest req){
		MyUserDetail ud = (MyUserDetail) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		Map<String, Object> paramMap=new HashMap<String, Object>();
		paramMap.put("merchantId", ud.getMerchantId());
		return statisticalService.getMerchantOfGoodsPageView(paramMap);
	}
	
	/**
	 * 店铺的销售金额统计（按日统计）
	 * @param paramMap
	 * @return
	 */
	@RequestMapping("web/getMerchantOfSalesMoney")
	@ResponseBody
	public List<Map<String,Object>> getMerchantOfSalesMoney(HttpServletRequest req){
		MyUserDetail ud = (MyUserDetail) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		Map<String, Object> paramMap=new HashMap<String, Object>();
		paramMap.put("merchantId", ud.getMerchantId());
		return statisticalService.getMerchantOfSalesMoney(paramMap);
	}
	
	/**
	 * 店铺统计商品的浏览量
	 * @return
	 */
	@RequestMapping("manager/getGoodsOfPageView")
	@ResponseBody
	public List<Map<String,Object>> getGoodsOfPageView(HttpServletRequest req){
		MyUserDetail ud = (MyUserDetail) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		return statisticalService.getGoodsOfPageView(ud.getMerchantId());
	}
	
	
}
